
// 
// File:   Agentsocket.h
// Author: dnazarov
//
// Created on 12 Октябрь 2009 г., 11:16
//

#ifndef _AGENTSOCKET_H
#define	_AGENTSOCKET_H

#include "sockets/TcpSocket.h"
#include "sockets/ISocketHandler.h"
#include <statgrab.h>
#include <vector>
#include <map>
#include "bot/data.h"
#include "cfgparser.h"
#include <list>



class Bot;

class AgentSocket : public TcpSocket
{
public:

    AgentSocket(ISocketHandler &, Data *d);
    ~AgentSocket();

    virtual void OnLine(const std::string&);

protected:

     void replace(std :: string &, const std :: string &,
                               const std :: string &);

private:

    const std::string getUptime();

    const std::string getOsName()
    {
        if (m_host_info) return (std::string)m_host_info->os_name;
    }

    const std::string getOsVersion()
    {
        if (m_host_info) return (std::string)m_host_info->os_version;
    }

    const std::string getHostname()
    {
        if (m_host_info) return (std::string)m_host_info->hostname;
    }
    const std::string checkProcesses();
    const std::string getProcesses();
    const std::string getCpuStat();
    const std::string getFsStat(bool is_checked = 0);
    const std::string getNetStat();
    const std::string getLoadStat(bool is_checked = 0);
    const std::string getMemStat(bool is_chesked = 0);
    const std::string getUsersStat();
    const std::string killProcess(const std::string &);
    const std::string ctrlService(const std::string &, const std::string &) const;
    void loadConfig();
    bool m_init, m_is_check_fs, m_is_check_ps, m_is_check_mem;
    sg_host_info * m_host_info;
    std::map<std::string, bool> * m_disk_array, * m_services;
    Data * m_data;

    const std::string toStr(int);
    const std::string toStr(float);
    const std::string toStr(double);
    const std::string toStr(long long);
   
    uint m_fs_threshold;
    float m_load_threshold;
    long long m_memory_threshold;
    const list<std::string> * m_alerts;
    std::string m_eol;
    const std::string * m_pathToService;
    void initDisks();
    uint m_countOfServices;
    const CfgParser * m_config;


};

#endif	/* _AgentSOCKET_H */

